<template>
  <div class="payWave" :id="id"></div>
</template>
<script>
  import echarts from 'echarts/lib/echarts'
  import 'echarts/lib/chart/line'
  import 'echarts/lib/component/legend'
  import 'echarts/lib/component/tooltip'
  import { mapActions, mapState} from 'vuex'
  export default {
    props: {
      id: {
        type: String,
        required: true
      },
      xAxis: {
        type: Array,
        required: true,
      },
      data: {
        type: Array,
        required: true,
      }
    },
    watch: {
      data (val, oldval) {
        this.onReady()
      }
    },
    mounted () {
      this.onReady()
    },
    methods: {
      onReady () {
        const { id, data, xAxis } = this
        const options = {
          tooltip: {
            trigger: 'axis',
            position: function (pos, params, dom, rect, size) {
              // 鼠标在左侧时 tooltip 显示到右侧，鼠标在右侧时 tooltip 显示到左侧。
              var obj = {top: 60}
              obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 5
              return obj
            },
            axisPointer: { type: 'shadow' },
            formatter: function (params) {
              let name = params[0].name
              let name0 = params[0].seriesName
              let value0 = params[0].value
              let dom = `${name}<br/>${name0}:${value0}万笔`
              return dom
            }
          },
          grid: {
            show: true,
            left: '3%',
            right: '4.5%',
            top: '4%',
            bottom: '3%',
            containLabel: true,
            backgroundColor: '#0e0f17',
            borderColor: '#0e0f17'
          },
          xAxis: [
            {
              type: 'category',
              boundaryGap: false,
              data: xAxis,
              axisLabel: {
                color: '#62e2ee'
              },
              axisLine: { show: false },
              axisTick: { show: false }
            }
          ],
          yAxis: [
            {
              type: 'value',
              axisLabel: {
                color: '#62e2ee',
                formatter: (value, index) => {
                  return parseInt(value) + '万'
                }
              },
              min: value => {return value.min},
//              max: 6000000,
              axisLine: { show: false }, // 取消边界线
              axisTick: { show: false }, // 取消数字轴上的刻度
              splitLine: { show: false } // 取消背景上的刻度
            }
          ],
          series: [
            {
              name: '支付笔数',
              type: 'line',
              smooth: true,
              symbol: 'circle',
              lineStyle: {
                normal: {
                  color: '#1c7dfa'
                }
              },
              data: data.map((item) => {
                return (parseInt(item) / 10000).toFixed(4)
              })
            }
          ],
          color: ['#1c7dfa']
        }
        const myWave = echarts.init(document.getElementById(id))
        myWave.setOption(options, true)
        window.addEventListener('resize', function () {
          myWave.resize()
        })
      }
    }
  }
</script>
<style lang="css" scoped>
  .payWave{
    width: 100%;
    height: 60%;
  }
</style>
